﻿
namespace Patterns4Net.Tests
{
    using System;
    using NUnit.Framework;

    public static class SafeAssert
    {
        public static void That(Func<bool> assertion, string message)
        {
            try
            {
                Assert.IsTrue(assertion.Invoke(), message);
            }
            catch (Exception e)
            {
                if (e is AssertionException)
                {
                    throw;
                }

                Assert.Fail(
                    string.Format(
                        "{0}. Exception {1} thrown, message: {2}",
                        message,
                        e.GetType().Name,
                        e.Message));
            }
        }
    }
}
